<template>
  <div class="my-tab-bar">
  	<div 
    @click="fn(index)" 
    class="tab-item" 
    v-for="(item,index) in tabList" 
    :key="item.text"
    :class="{'curcolor':currIndex===index}"
    >
      <!-- 图标 -->
      <span :class="'iconfont ' + item.icon"></span>
      <!-- 文字 -->
      <span>{{item.text}}</span>
    </div>
  </div>
</template>
<script>
// 1.定义一个变量currIndex设置下标值
// 2.给它设置一个点击事件,点击那个的时候就获取那个下标
// 3.然后动态新增一个类,让它等去它的下标
export default {
  data() {
    return {
      currIndex:0
    }
  },
  methods:{
    fn(index){
      this.$emit('changeName',index)
      this.currIndex = index
    }
  },
  props:{
    tabList:{
      type:Array,
      // 给他一个默认值,引用类型设置默认值要用函数返回
      default:()=>[]
    }
  }
}
</script>

<style  lang="less" scoped>
.my-tab-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: white;
  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
.curcolor{
  color: red;
  
}
.tab-item{
  cursor: pointer;
}
</style>